package com.pengpeng.android.activity;


import java.util.ArrayList;
import java.util.HashMap;

import com.pengpeng.android.activity.R;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;



public class FriendsManageActivity extends ListActivity {
	 /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.friendsmanage);  
          
        //生成一个ArrayList类型的变量list  
        ArrayList<HashMap<String, String>> list = loadList();
        //生成一个SimpleAdapter类型的变量来填充数据  
        SimpleAdapter listAdapter = new SimpleAdapter(this, list, R.layout.friendsmanage_list, new String[]{"user_name" , "user_phonenum"}, new int[]{R.id.user_name , R.id.user_phonenum});  
        //设置显示ListView  
        setListAdapter(listAdapter);  
          
    }  
    //重写onListItemClick但是ListView条目事件  
    @Override  
    protected void onListItemClick(ListView l, View v, int position, long id) {  
        // TODO Auto-generated method stub  
        super.onListItemClick(l, v, position, id);  
        //显示单击条目ID号  
        System.out.println("id = " + id);  
        //显示所单击条目的位置数  
        System.out.println("position = " + position);  
    }  
      
    private ArrayList<HashMap<String, String>> loadList()
    {
    	 //生成一个ArrayList类型的变量list  
        ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String,String>>();  
        //生成两个HashMap类型的变量map1 ， map2  
        //HashMpa为键值对类型。第一个参数为建，第二个参数为值  
        HashMap<String, String> map1 = new HashMap<String, String>();  
        HashMap<String, String> map2 = new HashMap<String, String>();  
        //把数据填充到map1和map2中。  
        map1.put("user_name", "张三");  
        map1.put("user_ip", "192.168.1.52");  
          
        map2.put("user_name", "李四");  
        map2.put("user_ip", "192.168.0.1");  
        //把map1和map2添加到list中  
        list.add(map1);  
        list.add(map2);  
        return list;
    }
}